#include "greekalphabetdialog.h"
#include "ui_greekalphabetdialog.h"
#include <QTableWidgetItem>

GreekAlphabetDialog::GreekAlphabetDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::GreekAlphabetDialog)
{
    ui->setupUi(this);
    setModal(false);
    ui->tableWidget->setColumnCount(ColCount);
    ui->tableWidget->setRowCount(RowCount);
    ui->tableWidget->horizontalHeader()->hide();
    ui->tableWidget->verticalHeader()->hide();
    for (int i = 0; i < RowCount; ++i)
        ui->tableWidget->setRowHeight(i, CellSize);
    for (int i = 0; i < ColCount; ++i)
        ui->tableWidget->setColumnWidth(i, CellSize);

    ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);

    for (int i = 0; i < RowCount; ++i) {
        for (int j = 0; j < ColCount; ++j) {
            QTableWidgetItem *item = new QTableWidgetItem();
            item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
            int n = getNumberOfSymbol(i, j);
            ui->tableWidget->setIconSize(QSize(30, 30));
            item->setIcon(QIcon(QString(":/symbols/symbl%1.png").arg(n)));
            ui->tableWidget->setItem(i,j, item);
        }
    }

    connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellClicked(int,int)));
}
//-----------------------------------------------------------------------------

GreekAlphabetDialog::~GreekAlphabetDialog()
{
    delete ui;
}
//-----------------------------------------------------------------------------

void GreekAlphabetDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
//-----------------------------------------------------------------------------

void GreekAlphabetDialog::cellClicked(int row, int column)
{
    int n = getNumberOfSymbol(row, column);
    emit addSymbol(alphabet[n]);
}
//-----------------------------------------------------------------------------

const QString GreekAlphabetDialog::alphabet[NumSymbol]={
    "&alpha;",
    "&beta;",
    "&gamma;",
    "&delta;",
    "&epsilon;",
    "&zeta;",
    "&eta;",
    "&theta;",
    "&iota;",
    "&kappa;",
    "&lambda;",
    "&mu;",
    "&nu;",
    "&xi;",
    "&omicron;",
    "&pi;",
    "&rho;",
    "&sigma;",
    "&sigmaf;",
    "&tau;",
    "&upsilon;",
    "&phi;",
    "&chi;",
    "&psi;",
    "&omega;",
    "&Gamma;",
    "&Delta;",
    "&Theta;",
    "&Lambda;",
    "&Xi;",
    "&Pi;",
    "&Sigma;",
    "&Upsilon;",
    "&Phi;",
    "&Psi;",
    "&Omega;"
};
//-----------------------------------------------------------------------------

int GreekAlphabetDialog::getNumberOfSymbol(int row, int column) const
{
    int res = row * ColCount + column;
    if (res >= NumSymbol || res < 0)
        return -1;
    return res;
}
//-----------------------------------------------------------------------------




